This assignment is optional, and I encourage you to share your solutions with me and your peers in the discussion forums!
To complete this assignment, create a code cell that:
pyplot subplots
or matplotlib gridspec
functionality.x1
, x2
, x3
, x4
) for each plot and plotting this as we did in the lecture on animation.Tips:
In [4]:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
%matplotlib notebook
# generate 4 random variables from the random, gamma, exponential, and uniform distributions
x1 = np.random.normal(-2.5, 1, 10000)
x2 = np.random.gamma(2, 1.5, 10000)
x3 = np.random.exponential(2, 10000)+7
x4 = np.random.uniform(14,20, 10000)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex=True, sharey=True)
n = 100
def update(curr):
if curr == n:
a.event_source.stop()
else:
plt.gcf()
ax1.hist(x1[:curr], normed=True, bins=10, alpha=0.5)
ax2.hist(x2[:curr], normed=True, bins=10, alpha=0.5)
ax3.hist(x3[:curr], normed=True, bins=10, alpha=0.5)
ax4.hist(x4[:curr], normed=True, bins=10, alpha=0.5)
plt.axis([-7,21,0,0.6])
a = animation.FuncAnimation(fig, update, interval=10)
In [ ]:
In [ ]: